<template>
	<view class="tzgg">
		<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Rectangle 21541@2x.png" class="tzggback" mode=""></image>
		<headertop title="通知公告" str1="oridei" :back1="back1"></headertop>
		<view class="content">
			<view class="itembox" v-for="(item,index) in list" :key="index" @click="gopage(item)">
				<view class="centertext">
					<view class="t1">
						<view class="reduce" v-if="item.is_show==0">

						</view>
						{{item.title}}
					</view>
					<view class="miaoshu">
						{{item.detail}}
					</view>
					<view class="timeline">
						<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Frame@2x(27).png" class="icon" mode=""></image>
						{{timestampfun(item.createtime*1000)}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import headertop from '@/components/header.vue'
	import {
		onLoad,
		onShow,
		onPageScroll
	} from "@dcloudio/uni-app";
	import {
		noticelist
	} from '@/api/home.js'
	import {
		reactive,
		ref
	} from 'vue'
	const back1 = ref('')
	const query = reactive({
		page: 1,
		limit: 10
	})
	const lastpage = ref(0)
	const list = ref([])
	onShow(() => {
		list.value = []
		query.page = 1
		initlist()
	})
	onPageScroll((e) => {
		if (e.scrollTop > 100) {
			back1.value = '#92C487'
		} else {
			back1.value = ''
		}
		if (query.page < lastpage.value) {
			query.page++
			initlist()
		}
	})
	async function initlist() {
		const res = await noticelist(query)
		console.log(res, 'res---------------');
		if (res.data.code == 1) {
			list.value.push(...res.data.data.list)
			lastpage.value = res.data.data.lastpage
		}
	}


	function gopage(item) {
		console.log('11111111111111', item);
		uni.navigateTo({
			url: '/sub_index/index/activedetail?id=' + item.id + '&title=详情'
		})
	}

	function timestampfun(time) {
		const date = new Date(time);
		const year = date.getFullYear();
		const month = String(date.getMonth() + 1).padStart(2, "0");
		const day = String(date.getDate()).padStart(2, "0");
		const hours = String(date.getHours()).padStart(2, "0");
		const minutes = String(date.getMinutes()).padStart(2, "0");
		const seconds = String(date.getSeconds()).padStart(2, "0");
		const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
		return formattedDate
	}
</script>

<style lang="scss">
	.tzgg {
		width: 100%;
		overflow: hidden;
		position: relative;

		.tzggback {
			width: 750rpx;
			height: 500rpx;
			position: absolute;
			z-index: -1;
		}

		.content {
			width: 100%;
			overflow: hidden;
			margin-top: 196rpx;
			overflow: hidden;
			z-index: 999;

			.itembox {
				width: 686rpx;
				background: #FFFFFF;
				overflow: hidden;
				box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(0, 0, 0, 0.15);
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				margin: auto;
				margin-bottom: 24rpx;
				overflow: hidden;

				.centertext {
					width: 632rpx;
					margin: auto;
					white-space: nowrap;
					/* 禁止文本换行 */
					overflow: hidden;
					/* 隐藏超出范围的内容 */
					text-overflow: ellipsis;

					.t1 {
						font-family: PingFang SC, PingFang SC;
						font-weight: bold;
						font-size: 32rpx;
						color: #1D2129;
						margin-top: 32rpx;
						white-space: nowrap;
						/* 禁止文本换行 */
						/* 隐藏超出范围的内容 */
						position: relative;
						display: inline-block;

						/* 使用省略号 */
						.reduce {
							width: 12rpx;
							height: 12rpx;
							background: #FF2538;
							border-radius: 50%;
							position: absolute;
							top: 0%;
							right: -12%;
						}
					}

					.timeline {
						width: 100%;
						margin-top: 30rpx;
						display: flex;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #86909C;
						align-items: center;
						margin-bottom: 32rpx;

						.icon {
							width: 32rpx;
							height: 32rpx;
							margin-right: 8rpx;
						}

					}

					.miaoshu {
						width: 100%;
						margin-top: 28rpx;
						overflow: hidden; //：隐藏超出容器范围的内容。

						text-overflow: ellipsis; //：使用省略号表示被隐藏的文本。

						display: -webkit-box; //：将元素设置为WebKit内核的弹性盒子模型。

						-webkit-line-clamp: 2; //：限制显示的文本行数为三行。

						-webkit-box-orient: vertical; //：设置弹性盒子的排列方向为垂直。
					}
				}
			}
		}
	}
</style>